package com.digitalchina.lxnsy.api;

import android.app.Activity;
import android.os.Handler;

import com.digitalchina.lxnsy.constant.MSG;
import com.digitalchina.lxnsy.constant.URL;
import com.digitalchina.lxnsy.toolkit.OkHttpUtil;
import com.digitalchina.lxnsy.xml.UserXML;
import com.lzy.okhttputils.model.HttpParams;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.api
 * 创建人：郑皓
 * 创建时间：2017/2/10 17:14
 * 修改备注：
 * ================================================
 */
public class BusinessQandA {

    /**
     * 提问
     *
     * @param activity
     * @param title             标题
     * @param content           内容
     * @param noFormaterContent 无格式内容
     * @param handler
     */
    public static void addQuestion(Activity activity, String title, String content, String noFormaterContent, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("title", title);
        params.put("content", content);
        params.put("noFormaterContent", noFormaterContent);
        params.put("userId", UserXML.getId(activity));

        OkHttpUtil.post(activity, URL.URL_ADD_QUESTION, "请稍候...", params, handler, MSG.MSG_ADD_QUESTION_SUCCESS, MSG.MSG_ADD_QUESTION_FIELD);

    }

    /**
     * 帮助与支持获取相似问题
     *
     * @param activity
     * @param offset
     * @param limit
     * @param keywords 关键字 必填
     * @param handler
     */
    public static void getsimilarquestionlist(Activity activity, String offset, String limit, String keywords, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("offset", offset);
        params.put("limit", limit);
        params.put("keywords", keywords);

        OkHttpUtil.post(activity, URL.URL_GET_SIMILAR_QUESTION_LIST, "", params, handler, MSG.MSG_GET_SIMILAR_QUESTION_LIST_SUCCESS, MSG.MSG_GET_SIMILAR_QUESTION_LIST_FIELD);

    }


    /**
     * 问题答案列表
     *
     * @param activity
     * @param questionId 问题id
     * @param handler
     */
    public static void showDetails(Activity activity, String questionId, String page, String limit, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("id", questionId);
        params.put("page", page);
        params.put("limit", limit);
        params.put("userId", UserXML.getId(activity));
        params.put("useraccId", UserXML.getUserId(activity));

        OkHttpUtil.post(activity, URL.URL_SHOW_DETAILS, "", params, handler, MSG.MSG_SHOW_DETAILS_SUCCESS, MSG.MSG_SHOW_DETAILS_FIELD);

    }


    /**
     * 删除问题
     *
     * @param activity
     * @param questionId 问题id
     * @param handler
     */
    public static void deleteQuestion(Activity activity, String questionId, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("id", questionId);

        OkHttpUtil.post(activity, URL.URL_DELETE_QUESTION, "", params, handler, MSG.MSG_DELETE_QUESTION_SUCCESS, MSG.MSG_DELETE_QUESTION_FIELD);

    }

    /**
     * 删除回答(用户自己的回答)
     *
     * @param activity
     * @param answerId 回答id
     * @param handler
     */
    public static void deleteAnswer(Activity activity, String answerId, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("id", answerId);
        params.put("useraccId", UserXML.getUserId(activity));

        OkHttpUtil.post(activity, URL.URL_DELETE_ANSWER, "", params, handler, MSG.MSG_DELETE_ANSWER_SUCCESS, MSG.MSG_DELETE_ANSWER_FIELD);

    }


    /**
     * 回答问题
     *
     * @param activity
     * @param questionId      问题id
     * @param answerContent   答案内容
     * @param noFormatContent 无格式的答案
     * @param handler
     */
    public static void answerQuestion(Activity activity, String questionId, String answerContent, String noFormatContent, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("questionId", questionId);
        params.put("answerContent", answerContent);
        params.put("noFormatContent", noFormatContent);
        params.put("userId", UserXML.getId(activity));

        OkHttpUtil.post(activity, URL.URL_ANSWER_QUESTION, "", params, handler, MSG.MSG_ANSWER_QUESTION_SUCCESS, MSG.MSG_ANSWER_QUESTION_FIELD);

    }


    /**
     * 修改提问
     *
     * @param activity
     * @param questionId      问题id
     * @param content         答案内容
     * @param noFormatContent 无格式的内容
     * @param handler
     */
    public static void modifyQuestion(Activity activity, String questionId, String content, String noFormatContent, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("id", questionId);
        params.put("content", content);
        params.put("noFormaterContent", noFormatContent);

        OkHttpUtil.post(activity, URL.URL_MODIFY_QUESTION, "", params, handler, MSG.MSG_MODIFY_QUESTION_SUCCESS, MSG.MSG_MODIFY_QUESTION_FIELD);

    }


    /**
     * 咨询历史详情
     *
     * @param activity
     * @param questionId 问题id
     * @param handler
     */
    public static void getSimilarQuestionDetail(Activity activity, String questionId, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("id", questionId);

        OkHttpUtil.post(activity, URL.URL_GET_SIMILAR_QUESTION_DETAIL, "", params, handler, MSG.MSG_GET_SIMILAR_QUESTION_DETAIL_SUCCESS, MSG.MSG_GET_SIMILAR_QUESTION_DETAIL_FIELD);

    }

}
